package net.butov.wrappers.partialimplemntation;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author Maxim Butov
 * @version $Id$
 */
public class Helper {

    public static <T> T createPartialImplementation(Class<T> abstractClass) {

        Enhancer enhancer = new Enhancer();

        enhancer.setSuperclass(abstractClass);
        enhancer.setInterfaces(abstractClass.getInterfaces());

        enhancer.setCallback(new MethodInterceptor() {

            public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                return methodProxy.invokeSuper(proxy, args);
            }
        });

        return (T) enhancer.create();
    }
}
